<template>
	<div>
		<div class="k" style="width: 100%;height: 50px;"></div>
		<div id="b" style="width: 1600px; margin-left: calc(50% - 800px);">
			<el-table :data="veg" style="1000px" height="800px">
				<el-table-column prop='vid' label="菜品编号"></el-table-column>
				<el-table-column prop='vname' label="菜品名称"></el-table-column>
				<el-table-column prop='vprice' label="菜品原价"></el-table-column>
				<el-table-column prop='vipprice' label="菜品会员价"></el-table-column>
				<el-table-column label="操作">
					<template slot-scope="owner">
						<el-button @click="yj(owner.row.vid)">更改原价</el-button>
						<el-button @click="hyj(owner.row.vid)">更改会员价</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>
	</div>
</template>

<script>
	export default {
		data: function() {
			return {
				veg: [],
			}
		},
		created: function() {
			this.queryveg();
		},
		methods: {
			queryveg: function() {
				this.$http.get("http://localhost:8080/OrderSystemServer/order/veg/show")
					.then((response) => {
						this.veg = response.data.body;
						//console.log(this.veg);
					});
			},
			yj: function(vid) {
				this.$prompt('请输入新的价格', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(({
					value
				}) => {
					this.$message({
						type: 'success',
						message: '新的价格是: ' + value
					});
					this.$http.get(`http://localhost:8080/OrderSystemServer/order/veg/updateprice?vid=${vid}&nprice=${value}`)
						.then((response) => {
							if(response.data.isOK) {
								this.$message({
									type: 'success',
									message: '更改成功'
								});
								this.queryveg();
							}
						});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消输入'
					});
				});

			},
			hyj: function(vid) {
				this.$prompt('请输入新的价格', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(({
					value
				}) => {
					this.$message({
						type: 'success',
						message: '新的价格是: ' + value
					});
					this.$http.get(`http://localhost:8080/OrderSystemServer/order/veg/updatevipprice?vid=${vid}&nvipprice=${value}`)
						.then((response) => {
							if(response.data.isOK) {
								this.$message({
									type: 'success',
									message: '更改成功'
								});
								this.queryveg();
							}
						});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消输入'
					});
				});

			}
			
		}
	}
</script>

<style>

</style>